home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Drawing / Rectangle.h < prev    next >
Text File  |  1997-06-28  |  3KB  |  92 lines

  1. // Rectangle.h
  2.  
  3. #ifndef Rectangle_h
  4. #define Rectangle_h
  5.  
  6. #ifndef PointObject_h
  7. #include "PointObject.h"
  8. #endif
  9. #ifndef Range_h
  10. #include "Range.h"
  11. #endif
  12.  
  13. class Rectangle: public Rect
  14.   {
  15.     public:
  16.         Rectangle()                                                        {}
  17.         Rectangle( const Rect& r )            : Rect( r )            {}
  18.         Rectangle( int16 l, int16 t, int16 r, int16 b )        { left = l; top = t; right = r; bottom = b; }
  19.         Rectangle( Point p1, Point p2 );
  20.         
  21.         static const Rectangle big;
  22.         static const Rectangle zero;
  23.         
  24.         PointObject TopLeft() const                                { return PointObject( left, top ); }
  25.         PointObject TopRight() const                                { return PointObject( right, top ); }
  26.         PointObject BottomLeft() const                            { return PointObject( left, bottom ); }
  27.         PointObject BottomRight() const                            { return PointObject( right, bottom ); }
  28.         
  29.         void SetTopLeft( Point p )                                    { left = p.h; top = p.v; }
  30.         void SetTopRight( Point p )                                { right = p.h; top = p.v; }
  31.         void SetBottomLeft( Point p )                                { left = p.h; bottom = p.v; }
  32.         void SetBottomRight( Point p )                            { right = p.h; bottom = p.v; }
  33.  
  34.         bool IsEmpty() const                                            { return left >= right || top >= bottom; }
  35.         bool IsNormal() const                                        { return left <= right && top <= bottom; }
  36.         bool Contains( Point p ) const;
  37.         bool StrictlyContains( Point p ) const;
  38.         bool WeaklyContains( Point p ) const;
  39.         
  40.         void operator=( Rect r )                                    { *(Rect *)this = r; }
  41.         
  42.         bool operator==( Rect r ) const;
  43.         bool operator!=( Rect r ) const                            { return !(*this == r); }
  44.         bool operator<=( Rect r ) const;
  45.         bool operator>=( Rect r ) const;
  46.         bool operator<( Rect r ) const                            { return *this <= r && *this != r; }
  47.         bool operator>( Rect r ) const                            { return *this >= r && *this != r; }
  48.         
  49.         void operator&=( Rect r );
  50.         void operator|=( Rect r );
  51.         Rectangle operator&( Rect r ) const;
  52.         Rectangle operator|( Rect r ) const;
  53.  
  54.         bool Intersects( Rect r ) const;
  55.         bool Touches( Rect r ) const;
  56.         
  57.         uint32 SharedSides( Rect r ) const;
  58.         
  59.         void operator+=( Rect r );
  60.         void operator-=( Rect r );
  61.         Rectangle operator+( Rect r ) const;
  62.         Rectangle operator-( Rect r ) const;
  63.         
  64.         void Inset( int16 amount );
  65.         void Inset( Point amount );
  66.         void Inset( Rect amount );
  67.         void Outset( int16 amount );
  68.         void Outset( Point amount );
  69.         void Outset( Rect amount );
  70.         
  71.         void operator+=( Point vector );
  72.         void operator-=( Point vector );
  73.         Rectangle operator+( Point vector ) const;
  74.         Rectangle operator-( Point vector ) const;
  75.         
  76.         uint32 Height() const                        { return uint32( bottom ) - uint32( top ); }
  77.         uint32 Width() const                            { return uint32( right ) - uint32( left ); }
  78.         PointObject Size() const;
  79.         uint32 Bulk() const;
  80.         uint32 Area() const;
  81.         uint32 TaxicabDistanceTo( Point p ) const;
  82.         uint32 TaxicabDistanceTo( Rect r ) const;
  83.         
  84.         Range<int16> Vertical() const                { return Range<int16>( top, bottom ); }
  85.         Range<int16> Horizontal() const            { return Range<int16>( left, right ); }
  86.  
  87.         void GlobalToLocal();
  88.         void LocalToGlobal();
  89.   };
  90.  
  91. #endif
  92.